#!/usr/bin/perl
#index.cgi

require './datetime-lib.pl';

&header($text{'datetime_title'}, "","index", 0, 1, undef, undef, "<meta http-equiv=refresh content=30>");

print "<form action='save_datetime.cgi' method=post onsubmit='document.forms[0].saveok.disabled = true;'>\n";
print "<table class=mode1>\n";
print "<tr><td width=100><b>$text{'date'}</b></td>\n";

$rawyear = `date +%Y`;
chop($rawyear);
print "<td><select name=year>\n";
for ($i = 1969; $i < 2051; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i eq $rawyear)?"selected":"";
}
print "</select>$text{'year'}</td>\n";

$rawmonth = `date +%m`;
chop($rawmonth);
print "<td><select name=month>\n";
for ($i = 1; $i < 13; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawmonth )?"selected":"";
}
print "</select>$text{'month'}</td>\n";

$rawday = `date +%e`;
print "<td><select name=day>\n";
for ($i = 1; $i < 32; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawday)?"selected":"";
}
print "</select>$text{'day'}</td></tr>\n";


print "<tr><td><b>$text{'time'}</b></td>\n";

$rawhour = `date +%H`;
chop($rawhour);
print "<td><select name=hour>\n";
for ($i = 0; $i < 24; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawhour)?"selected":"";
}
print "</select>$text{'hour'}</td>\n";

$rawmin = `date +%M`;
chop($rawmin);
print "<td><select name=minute>\n";
for ($i = 0; $i < 60; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawmin)?"selected":"";
}
print "</select>$text{'minute'}</td>\n";

$rawsec = `date +%S`;
chop($rawsec);
print "<td><select name=second>\n";
for ($i = 0; $i < 60; $i++)
{
	printf "<option %s value='$i'>$i\n", ($i == $rawsec)?"selected":"";
}
print "</select>$text{'second'}</td></tr>\n";

print "<tr><td><b>$text{'zone'}</b></td>\n";
print "<td colspan=3><select name=zone>\n";
$zonelink = readlink($config{'zonelink'});
print "<option value='Asia/Shanghai'>$text{'noselect'}(Asia/Shanghai)\n";
open(TAB, "$config{'zonetab'}.$gconfig{'lang'}");
while(<TAB>) {
	s/\r|\n//g;
	s/#.*$//;
	if (/^\((.*)\)\s+(\S+)/)
	{
		#if( !-f "$config{'zonedir'}/$2" ) { next; }
		printf "<option %s value='$2'>%s\n", ("$config{'zonedir'}/$2" eq $zonelink)?"selected":"", $1;
	}
}
close(TAB);
print "</select></td></tr>\n";
print "</table>\n";
print "<input type=submit name=saveok class=button1 value='$text{'submit'}'>\n";
print "</form>\n";

&footer("/", $text{'index'});
